<?php
if (!defined('IN_RJ')) die("Error 404");
if (!$logged_in && $conf['must_login_to_play']) die($lang['login_to_play']);
$id = $_GET['id'];
$type = $_GET['type'];
header("Content-Type: application/xml; charset=utf-8");

if(!$cached['xml'][$type][$id]) {
$xml = '<?xml version="1.0" encoding="utf-8"?>'.
	'<playlist version="1" xmlns="http://xspf.org/ns/0/">'.
	'<trackList>';
	
// Play  Song
if ($type == 1) {
	$r = $DB->fetch_row($DB->query("SELECT * FROM ".$conf['prefix']."media WHERE m_id IN ('".$id."')"));
	$r['m_url']=$func->unhtmlchars($r['m_url']);
	if($r['m_is_local'])
		$url=$func->get_server($r['m_is_local'],$r['m_url']);
	else{
		$type_qr=$DB->query("SELECT player_isgrab,player_img FROM ".$conf['prefix']."player WHERE player_id=".$r['m_type']);
		$type_chek=$DB->fetch_row($type_qr);
		$url=($type_chek['player_isgrab'])?($func->grab_link($r['m_url'])):$r['m_url'];
		$meta_type=explode(".",$type_chek['player_img']);
	}		
	$info = $conf['web_url']."/?act=img&id=".$r['m_id'];
		$xml .= '<track>'.
			'<Title><![CDATA['.$func->unhtmlchars($r['m_title']).']]></Title>'.
			'<creator><![CDATA['.$func->unhtmlchars($func->get_data('singer',$r['m_singer'])).']]></creator>'.
			'<location><![CDATA['.$url.']]></location>'.
			'<image><![CDATA['.$info.']]></image>'.
			'<meta rel="type">'.$meta_type[0].'</meta>'.
			'</track>';
}
// Play  EPISODE
if ($type == 2) {
	$r = $DB->fetch_row($DB->query("SELECT * FROM ".$conf['prefix']."media WHERE m_id IN ('".$id."')"));
	$r['m_url']=$func->unhtmlchars($r['m_url']);
	if($r['m_is_local'])
		$url=$func->get_server($r['m_is_local'],$r['m_url']);
	else{
		$type_qr=$DB->query("SELECT player_isgrab FROM ".$conf['prefix']."player WHERE player_id=".$r['m_type']);
		$type_chek=$DB->fetch_row($type_qr);
		$url=($type_chek['player_isgrab'])?($func->grab_link($r['m_url'])):$r['m_url'];
	}		
	$info = $conf['web_url']."/?act=img&id=".$r['m_id'];
		$xml .= '<track>'.
			'<Title><![CDATA['.$func->unhtmlchars($r['m_title']).']]></Title>'.
			'<location><![CDATA['.$url.']]></location>'.
			'<meta rel="type">flv</meta>'.
			'</track>';
}
// Play Singer
elseif ($type == 3) {
	$q = $DB->query("SELECT * FROM ".$conf['prefix']."data WHERE m_singer IN ('".$id."') AND m_type IN ('2','4','5') AND m_allow_mem=1");
	$singer_name = m_get_data('SINGER',$id);
	while ($r = $DB->fetch_row($q)) {
		$url = ($r['m_is_local'])?$mediaFolder[$r['m_is_local']].'/'.$r['m_url']:$r['m_url'];
		$url = m_encodelink($url);
		$info = (m_get_config('rewrite_url'))?'Info/'.$r['m_id'].'.png':'?img='.$r['m_id'];
			$xml .= '<track>'.
				'<Title>'.m_unhtmlchars($r['m_title']).'</Title>'.
				'<creator>'.m_unhtmlchars($singer_name).'</creator>'.
				'<location>'.$url.'</location>'.
				'<image>'.$info.'</image>'.
				'</track>';
	}
}
// Play Album
elseif ($type == 4) {
	$q = $DB->query("SELECT * FROM ".$conf['prefix']."data WHERE m_album IN ('".$id."') AND m_type IN ('2','4','5') AND m_allow_mem=1");
	while ($r = $DB->fetch_row($q)) {
		$url = ($r['m_is_local'])?$mediaFolder[$r['m_is_local']].'/'.$r['m_url']:$r['m_url'];
		$url = m_encodelink($url);
		$info = (m_get_config('rewrite_url'))?'Info/'.$r['m_id'].'.png':'?img='.$r['m_id'];
			$xml .= '<track>'.
				'<Title>'.m_unhtmlchars($r['m_title']).'</Title>'.
				'<creator>'.m_unhtmlchars(m_get_data('SINGER',$r['m_singer'])).'</creator>'.
				'<location>'.$url.'</location>'.
				'<image>'.$info.'</image>'.
				
			'</track>';
	}
}
// Play Playlist
elseif ($type == 5) {
	if($id =='session') $playlist = $_SESSION['playlist'];
	else $playlist = m_get_data('PLAYLIST',$id,"playlist_contents");
	if($playlist) {
		$q = $DB->query("SELECT * FROM ".$conf['prefix']."data WHERE m_id IN (".$playlist.") AND m_type IN ('2','4','5') AND m_allow_mem=1");
		while ($r = $DB->fetch_row($q)) {
			$url = ($r['m_is_local'])?$mediaFolder[$r['m_is_local']].'/'.$r['m_url']:$r['m_url'];
			$url = m_encodelink($url);
			$info = (m_get_config('rewrite_url'))?'Info/'.$r['m_id'].'.png':'?img='.$r['m_id'];
			$xml .= '<track>'.
				'<Title>'.m_unhtmlchars($r['m_title']).'</Title>'.
				'<creator>'.m_unhtmlchars(m_get_data('SINGER',$r['m_singer'])).'</creator>'.
				'<location>'.$url.'</location>'.
				'<image>'.$info.'</image>'.
				'</track>';
		}
	}
}
$xml .= '</trackList>'.
	'</playlist>';
	$cached['xml'][$type][$id] = $xml;
}
echo $cached['xml'][$type][$id];
exit();
?>